import time
import pytest
import allure
import TestCase

from Base.InitDriver import init_driver
from Page.CommonPage import CommonPage
from Utils.XiaoMaUtils import XiaoMaUtils


@allure.feature('TestCase_09: 每个月份下面对应的日期数量对应		')
@allure.issue(
    'https://www.tapd.cn/54441127/sparrow/tcase/view/1154441127001050214?url_cache_key=5b07a59231afaf505fb7dc2f4205dfae')
class TestCaseCalendar09:
    def setup_class(self):
        self.driver = init_driver()
        # 实例化页面
        # 桌面
        self.launcher_index_page = CommonPage(self.driver).get_launcher_index_page()
        self.launcher_app_list_page = CommonPage(self.driver).get_launcher_app_list_page()
        # 日历
        self.calendar_index_page = CommonPage(self.driver).get_calendar_index_page()

    def teardown_class(self):
        XiaoMaUtils.close_app('schedule')
        # XiaoMaUtils.clear_data('personal')
        self.driver.quit()

    @allure.story('step1:点击应用页')
    @pytest.mark.run(order=91)
    def test_calendar_09_1_click_list(self):
        try:
            self.launcher_index_page.click_app_list()
        except Exception as e:
            raise e
        finally:
            allure.attach(self.driver.get_screenshot_as_png(), XiaoMaUtils.get_current_time(),
                          allure.attachment_type.PNG)

    @allure.story("step2: 点击列表中的日历图标")
    @pytest.mark.run(order=92)
    def test_calendar_09_2_click_calendar(self):
        try:
            self.launcher_app_list_page.click_appname(TestCase.CALENDAR)
            self.calendar_index_page.is_display_calender_index()
        except Exception as e:
            raise e
        finally:
            allure.attach(self.driver.get_screenshot_as_png(), XiaoMaUtils.get_current_time(),
                          allure.attachment_type.PNG)

    @allure.story("step3: 每个月份下面对应的日期数量对应")
    @pytest.mark.run(order=93)
    def test_calendar_09_3_click_calendar(self):
        try:
            a = []
            i = 0
            for i in range(35):
                # print(i)
                num = i + 1
                text1 = self.calendar_index_page.get_ele_text(self.calendar_index_page.get_date_fate(index=num))
                a.append(text1)
                if text1 == '1':
                    print('进入当前月份的第一天')
                elif text1 == '31':
                    print('进入当前月份的最后一天')
                    break
                else:
                    print('当前代码的月份设置不正确请重新设置')
            i += 1
            # print(a)
        except Exception as e:
            raise e
        finally:
            allure.attach(self.driver.get_screenshot_as_png(), XiaoMaUtils.get_current_time(),
                          allure.attachment_type.PNG)


if __name__ == 'main__':
    # pass
    pytest.main("-s testcase_calendar_09.py")
